package com.naiterui.ehp.bs.recommend.repository.mysql;

import java.util.Collection;

import com.naiterui.common.repository.core.BaseJpaRepository;
import com.naiterui.ehp.bs.recommend.bean.MedicationRequire;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Repository;

@Repository
public interface IMedicationRequireRepository extends BaseJpaRepository<MedicationRequire, Long> {

    /**
     * 根据外部ID查询求药单数量
     * IMedicationRequireDao.getMedicationRequireByExtIdCount()
     *
     * @param doctorId
     * @param patientId
     * @param extId
     * @return
     * @Author guoyongxiang
     * @Date 2016年4月20日
     * @since 2.3.0
     */
    long countByDoctorIdAndPatientIdAndExtId(Long doctorId, Long patientId, String extId);


    /**
     * 根据医生患者ID分页查询求药记录
     * MedicationRequireDaoImpl.getRequiresByPage()
     *
     * @param patientId
     * @return
     * @Author guoyongxiang
     * @Date 2016年4月20日
     * @since 2.3.0
     */
    Page<MedicationRequire> findByPatientIdAndStatus(Long patientId, Integer status, Pageable pageable);

    /**
     * 根据医生和申请状态查询求药列表
     * @param doctorId
     * @param applyStatus
     * @return
     */
    Page<MedicationRequire> findByDoctorIdAndApplyStatusOrderByApplyStatusAscCreatedAtDesc(Long doctorId, Integer applyStatus, Pageable pageable);
    /**
     * 根据医生查询已续方和已暂停用药 求药列表
     * @param doctorId
     * @param applyStatus
     * @return
     */
    Page<MedicationRequire> findByDoctorIdAndApplyStatusGreaterThanOrderByApplyStatusAscCreatedAtDesc(Long doctorId, Integer applyStatus, Pageable pageable);

    /**
     * 根据医生查询求药列表
     * @param doctorId
     * @return
     */
    Page<MedicationRequire> findByDoctorIdOrderByApplyStatusAscCreatedAtDesc(Long doctorId, Pageable pageable);


    MedicationRequire findFirstByFormerRecommendId(Long formerRecommendId);

    Integer countByDoctorIdAndApplyStatusIn(Long doctorId, Collection<Integer> status);
}